import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
from transformers.models.bert.tokenization_bert import *
import torch
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DDIMScheduler
from diffusers.utils import load_image

# os.environ["http_proxy"] = "http://192.168.3.116:7890/"
# os.environ["https_proxy"] = "http://192.168.3.116:7890/"

import torch
from diffusers import StableDiffusionPipeline
from transformers import AutoTokenizer, CLIPTextModel

tokenizer_id = "lyua1225/clip-huge-zh-75k-steps-bs4096"
# tokenizer_id = "Midu/chinese-style-stable-diffusion-2-v0.1"
sd2_id = "Midu/chinese-style-stable-diffusion-2-v0.1"
# text_encoder = CLIPTextModel.from_pretrained(tokenizer_id).half().to("cuda")
tokenizer = AutoTokenizer.from_pretrained(tokenizer_id, trust_remote_code=True)
# scheduler = DDIMScheduler.from_pretrained(sd2_id, subfolder="scheduler")
pipe = StableDiffusionPipeline.from_pretrained(sd2_id, torch_dtype=torch.float16, tokenizer=tokenizer)
# pipe.scheduler = DDIMScheduler.from_pretrained(sd2_id, subfolder="scheduler")
# pipe = StableDiffusionPipeline.from_pretrained(sd2_id, torch_dtype=torch.float16)
pipe.to("cuda")

image = pipe("Cyberpunk style city streets, 8K resolution, CG rendering", guidance_scale=10, num_inference_steps=20).images[0]
image.save("cyberpunk.jpeg")